package com.java.test.system.fundstypemanage;

import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.system.fundstypemanage.dto.FundsTypeAddDTO;
import com.java.test.system.fundstypemanage.dto.FundsTypeDTO;
import com.java.test.system.fundstypemanage.dto.FundsTypeQueryDTO;
import com.java.test.system.fundstypemanage.dto.FundsTypeUpdateDTO;
import com.java.test.system.fundstypemanage.vo.FundsTypeVO;
import com.java.test.system.templatemember.dto.TemplateDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.Timer;

/**
 *  货币类型管理
 *  @author lijie1
 */
@Slf4j
@RestController
@RequestMapping("/systemConfig/fundsTypeManage")
public class FundsTypeController extends BaseController {
    @Autowired
    FundsTypeService fundsTypeService;
    private static Timer timer=new Timer();

    /**
     * 货币类型管理列表查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<FundsTypeVO>> getFundsTypeList(@RequestBody @Valid FundsTypeQueryDTO queryDTO) {
        log.info("----------货币类型管理列表查询----------");
        return fundsTypeService.getFundsTypeList(queryDTO);
    }

    /**
     * 货币类型管理新增
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResponseDTO<String> save(@RequestBody @Valid FundsTypeAddDTO addDTO, HttpServletRequest request) {
        log.info("----------货币类型管理添加----------");
        addDTO.setStatus(1);
        addDTO.setCreateTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-货币管理-货币类型添加");
        addDTO.setOperation(user.getLoginAccout());
        return fundsTypeService.save(addDTO);
    }

    /**
     * 通过id获取数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public ResponseDTO<FundsTypeVO> selectById(@RequestBody @Valid FundsTypeDTO dto) {
        log.info("----------货币类型管理查询----------");
        return fundsTypeService.selectById(dto.getId());
    }

    /**
     * 通过id修改数据
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseDTO<String> updateById(@RequestBody @Valid FundsTypeUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------货币类型管理修改----------");
        updateDTO.setModifyTime(new Date());
        updateDTO.setStatus(1);
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-货币管理-货币类型修改");
        return fundsTypeService.updateById(updateDTO);
    }

    /**
     * 通过id删除数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseDTO<String> deleteById(@RequestBody @Valid TemplateDTO dto, HttpServletRequest request) {
        log.info("----------货币类型管理删除----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-货币管理-货币类型删除");
        return fundsTypeService.deleteById(dto.getId());
    }

    /**
     * 通知游戏端数据变化
     * @return
     */
    @RequestMapping(value = "/messagePush",method = RequestMethod.POST)
    public ResponseDTO<String> messagePush(HttpServletRequest request) {
        log.info("----------通知游戏端数据变化----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-货币管理-通知游戏端");
        return fundsTypeService.messagePush();
    }
}
